package com.itheima.web;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by crowndint on 2018/10/1.
 *
 *  消息发布者
 *
 *    发布者、订阅模式
 *      就相当于发广播，可以有多个订阅者收到消息
 *
 *
 *   订阅者接收topic是需要在topic发布之前订阅；而生产/消费模式下，消息发出后会存放在队列中，等待消费者消费
 *
 *
 *
 */

@RestController
public class MsgPublisherController {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @RequestMapping("publishMsg")
    public void publishMsg(String text) {

        ActiveMQTopic topic = new ActiveMQTopic("msgDestination");
        jmsMessagingTemplate.convertAndSend(topic, text);
    }




}
